package cn.funeralobjects.ams.web.mapper;

import cn.funeralobjects.ams.model.Policy;
import cn.funeralobjects.ams.model.Statement;
import cn.funeralobjects.ams.model.StsAccessKey;
import cn.funeralobjects.ams.web.model.VPolicy;
import cn.funeralobjects.ams.web.model.VStatement;
import cn.funeralobjects.ams.web.model.VStsAccessKey;
import org.mapstruct.Mapper;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author FuneralObjects
 * Create date: 2020/6/8 7:13 AM
 */
@Mapper(componentModel = "spring")
public interface StsAccessKeyMapper {

    Statement toDto(VStatement vStatement);


    default Policy toDto(VPolicy vPolicy) {
        return vPolicy == null ? null : new Policy().setStatement(vPolicy.getStatement() == null ? null : vPolicy.getStatement().stream().map(this::toDto).collect(Collectors.toList()))
                .setVersion(vPolicy.getVersion());
    }

    default List<Policy> toDto(List<VPolicy> vPolicies) {
        return vPolicies.stream().map(this::toDto).collect(Collectors.toList());
    }

    VStsAccessKey toVo(StsAccessKey accessKey);
}
